package net.lahuobao.export.service.impl;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.springframework.stereotype.Service;

import net.lahuobao.export.datasoruce.annotation.ExportField;
import net.lahuobao.export.datasoruce.entity.enums.EYN;
import net.lahuobao.export.service.tranf.IEnumTranf;
@Service("enumTranfService")
public class EnumTranfImpl implements IEnumTranf {

	@Override
	public Object enumTranf(Object o, Field field ){
		String enumType=field.getAnnotation(ExportField.class).dictType();
		Object d=null;
		PropertyDescriptor propDesc = null;
		try {
			propDesc = new PropertyDescriptor(field.getName(),o.getClass());
		} catch (IntrospectionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Method methodGet=propDesc.getReadMethod();
		try {
			d=methodGet.invoke(o);
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(enumType.equals("EYN")){
			for(EYN e:EYN.values()){
						if(e.getValue().equals(d)){
							d=e.getName();
						}
			}
		}
		return d;
	}

	

}
